// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:mybase/base/tool/file/FFile.dart';
import 'package:mybase/base/tool/globalMethod/FFSafeValue.dart';
import 'package:mybase/base/tool/pprint/FFLog.dart';

///pod install提示 /Users/os/.pub-cache/hosted/pub.dev/XXXX/ios
Future<void> main() async {
  List<String> pNames = [
    "path_provider_foundation",
    "shared_preferences_foundation",
    "sqflite",
    "video_player_avfoundation",
  ];
  String flutterPluginPath = "/Users/os/.pub-cache/hosted/pub.dev/";

  print(flutterPluginPath);
  final directory = Directory(flutterPluginPath);
  if (await directory.exists()) {
    // 遍历目录中的内容
    List<FileSystemEntity> lists = directory.listSync();
    for (var element in lists) {
      if (element is Directory) {
        String folderName = element.path.split(Platform.pathSeparator).last;

        var iosDir = Directory("${element.path}/ios");
        if (await iosDir.exists()) {
          continue;
        }

        if (!folderName.startsWith(".") && folderName.contains("-")) {
          var parts = folderName.split("-");
          String pluginName = globalSafeValueFromList(parts, 0) ?? "";
          String pluginVersion = globalSafeValueFromList(parts, 1) ?? "";

          if (!pNames.contains(pluginName)) {
            continue;
          }
          String? content = await FFile.readAsString("/Users/os/led/test/create/flutter_plugin/uni_links.podspec");
          content = content.replaceAll("pluginName", pluginName);
          content =  content.replaceAll("pluginVersion", pluginVersion);
          FFLog.info(content);
          bool success = await FFile.writeContentByPath(filePath: "${element.path}/ios/${pluginName}.podspec", content: content,autoCreate: true);
          FFLog.result(success, "创建状态 $pluginName");
        }
      }
    }
  } else {
    print('目录不存在');
  }
}
